<template>
    <web-view
      :fullscreen="true"
      :src="webUrl"
      :webview-styles="webviewStyles"
    ></web-view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      src: '',
      webUrl: '', //https://ya30wxmp.hbwlife.com/myInfo.html#/   http://localhost:8080/myInfo.html#/
      webviewStyles: {
        progress: {
          color: '#FF3333',
        },
      },
    }
  },
  onLoad(option) {
    let src = decodeURIComponent(option.src)
    this.src = src
  },
  onShow() {
    let user_id = uni.getStorageSync('user_id')
    let access_token = uni.getStorageSync('access_token')
    let open_id = uni.getStorageSync('open_id')
    const pages = getCurrentPages()
    const currentPage = pages[pages.length - 1]
    const currentPath = currentPage.route
    //console.log('小程序当前页面路径:', currentPath)
    let data = {
      user_id,
      access_token,
      open_id,
      currentPath,
      time: new Date().getTime(),
    }

    let pathParams = ''
    if (
      typeof data === 'object' &&
      data !== null &&
      !Array.isArray(data) &&
      Object.keys(data).length > 0
    ) {
      for (let key in data) {
        pathParams += key + '=' + data[key] + '&'
      }
      pathParams = pathParams.slice(0, pathParams.length - 1)
    }
    if(this.src.indexOf('?')!== -1) {
      this.webUrl = this.src+'&'+pathParams
    }
    else {
      this.webUrl = this.src + '?' + pathParams
    }
  },
}
</script>
